<template>
	<el-dialog v-model="visible" :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" draggable width="70%">
		<el-form ref="dataFormRef" :model="dataForm" :rules="dataRules" style="height:250px;" label-width="120px" @keyup.enter="submitHandle()">
			<div class="divline">
				<el-form-item prop="userName" class="divlinecenter" label="责任人">
					<el-input v-model="dataForm.userName" placeholder="责任人" @click="addOrUpdateDeptHandle()"></el-input>
				</el-form-item>
			</div>
			<div class="divline">
				<el-form-item prop="typeName" class="divlinecenter" label="公海类型">
					<el-input v-model="dataForm.typeName" placeholder="公海类型" @click="addOrUpdateDeptHandle()"></el-input>
				</el-form-item>
			</div>
		</el-form>
		<template #footer>
			<div class="divbtn">
				<el-button @click="visible = false">取消</el-button>
				<el-button  v-auth="'sys:customer:save'" type="primary" @click="submitHandle()">确定</el-button>
			</div>
		</template>
		<!-- 弹窗, 新增 / 修改 -->
		<highseasList ref="highseasListRef" @fatherMethod="fatherMethod"></highseasList>
	</el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import { ElMessage } from 'element-plus/es'
import {useHighSeasSubmitApi,useHighSeasApi} from '@/api/sys/highseas'
import highseasList from './highseas.vue'
import {useCustomerSubmitApi,useCustomerApi} from '@/api/sys/customer'
const emit = defineEmits(['refreshDataList'])

const visible = ref(false)
const dataFormRef = ref()
const dataForm = reactive({
	id: 0,
	typeName:'',
	typeId:'',
	userName:'',
	userId:'',
	customerId:'',
	customerName:'',
	customerArea:'',
	customerType:'',
	customerChat:'',
	customerTel:'',
	customerStatus:'',
	customerRemark:'',
	currentId:'',
	deleted:0
})
const init = (obj:any) => {
	visible.value = true
	// 重置表单数据
	if (dataFormRef.value) {
		dataFormRef.value.resetFields()
	}
	// id 存在则为修改
	if (obj) {
		dataForm.currentId=obj.id;
		dataForm.userId=obj.userId;
		dataForm.userName=obj.userName;
		dataForm.customerArea=obj.customerArea;
		dataForm.customerStatus=obj.customerStatus;
		dataForm.customerTel=obj.customerTel;
		dataForm.customerChat=obj.customerChat;
		dataForm.customerType=obj.customerType;
		dataForm.customerName=obj.customerName;
		dataForm.currentId=obj.id;
		dataForm.customerId=obj.uid;
	}
}
const fatherMethod=(typeId:any,typeName:any)=>{
	dataForm.typeId=typeId;
	dataForm.typeName=typeName;
}
const highseasListRef = ref()
const addOrUpdateDeptHandle = () => {
	highseasListRef.value.init();
}
const dataRules = ref({
	typeName: [{ required: true, message: '必填项不能为空', trigger: 'blur' }]
})

// 表单提交
const submitHandle = () => {
	dataFormRef.value.validate((valid: boolean) => {
		if (!valid) {
			return false
		}
		useHighSeasSubmitApi(dataForm).then((res:any) => {
			let param={id:dataForm.currentId,deleted:1}
			useCustomerSubmitApi(param).then((res:any) => {
				ElMessage.success({
					message: '操作成功',
					duration: 500,
					onClose: () => {
						visible.value = false
						emit('refreshDataList')
					}
				})
			})
		})
	})
}

defineExpose({
	init
})
</script>


<style lang="scss" scoped>
.divline {
	width: 96%;
	height: 30px;
	float: left;
	margin-top: 20px;
}
.divfileline{
	width: 96%;
	float: left;
	margin-left: 40px;
	margin-top: 40px;
}
.divlineleft{
	width: 47%;
	float: left;
	height: 30px;
	padding-left: 10px;
}

.divlinecenter{
	width: 95.5%;
	float: left;
	height: 30px;
	padding-left: 10px;
}
.divbtn{
	text-align: center;
	margin-top: 20px;

}
.eduline{
	width: 96%;
	float: left;
	height: 50px;
	margin-top: 15px;
	border-bottom: 1px solid #BEBEBE;
	border-top: 1px solid #BEBEBE;
}
.divsplit{
	width: 96%;
	float: left;
	height: 1px;
	background-color:#409eff;
    margin-top: 5px;
}
.divsplit:last-child{
	width: 96%;
	float: left;
	height: 1px;
}
.eduitem{
	width: 20%;
	height: 30px;
	float: left;
    padding-top: 10px;
}
.inputVal.el-input__wrapper{
	width: 60%;
	float: left;
	height: 30px;
}
.inputVal.el-input{
	width: 60%;
	float: left;
	height: 30px;
}
.texttit{
	width: 30%;
	float: left;
	height: 30px;
	line-height: 2;
}
.eduitembtn{
	
	width: 19%;
	height: 30px;
	float: left;
    padding-top: 10px;
}
</style>
